$(function() {
	$('#vue_vm_list div').hide();
	
	_addChangeListener("#room_select", function() {
		var option = $('#room_select option:selected');
		if(view && view.data) {view.data.roomName = option.text();}
	});
});

var bed = {
	bedId: '',
	buildingId: '',
	floorId: '',
	roomId: '',
	bedNumber: '',
	useStatus: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	buildingName: '',
	floorName: '',
	roomName: '',
};

var view = {
	data: bed
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

function save() {
	view.data.bedNumber = (view.data.bedNumber==''? 0: parseInt(view.data.bedNumber));
	view.data.useStatus = (view.data.useStatus==''? 0: parseInt(view.data.useStatus));

	save_basic(path+'/bed/save', {bed:view.data}, function() {
		alert('新增床位成功');
		
		var roomId = $('#room_cond_select').val();
		if(load_bed_by_roomId && roomId && roomId!='') {
			load_bed_by_roomId(roomId);
		}
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/bed/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

load_bed_by_roomId = function(roomId) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	if(!roomId || roomId=='') {return;}
	
	find_basic_by_json(path+'/bed/findByRoomId', {roomId: roomId}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/bed/deleteBatch');
}
